define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/order/index' + location.search,
                   /* add_url: 'user/order/add',
                    edit_url: 'user/order/edit',*/
                    del_url: 'user/order/del',
                    multi_url: 'user/order/multi',
                    import_url: 'user/order/import',
                    table: 'user_order',
                }
            });

            var table = $("#table");
            //当表格数据加载完成时
            /*table.on('load-success.bs.table', function (e, data) {
                $('label[for="user.id"]').parent().css('display','none'); // 隐藏描述查询栏
            });*/

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'state', title: __('State'), searchList: {"1":__('State 1'),"2":__('State 2'),"3":__('State 3')/*,"4":__('State 4'),"6":__('State 6'),"7":__('State 7')*/}, formatter: Table.api.formatter.normal},
                        //{field: 'goods_id', title: __('Goods_id')},
                        {field: 'subsidy_money', title: __('Subsidy_money'), operate: false },
                        {field: 'residue_money', title: __('Residue_money'), operate: false },
                        {field: 'daily_money', title: __('daily_money'), operate: false },
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'paymenttime', title: __('Paymenttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.nickname', title: __('User.nickname'), operate: "LIKE"},
                        {field: 'user.id', title: __('UID'), operate: "=",visible:false},
                        {field: 'remarks', title: __('Remarks'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'goods',
                                    title: __('赠送商品'),
                                    classname: 'btn btn-xs btn-success btn-dialog',
                                    text: '赠送商品',
                                    //icon: 'fa fa-folder-o',
                                    url: function(row,column){
                                        var url='wanlshop/order/detail/id/'+row.order_id;
                                        return url;
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        if (row.level_id == 1) {
                                            return false
                                        }
                                        return true;

                                    },
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
